package com.zlq.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zlq.mapper.UserMapper;
import com.zlq.pojo.User;
import com.zlq.service.IUserService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
    @Resource
    public UserMapper userDao;

    public boolean save(User user) {
        int insert = userDao.insert(user);
        return false;
    }

    public void update(User user) {
        userDao.update(user, null);
    }

    public List<User> getAll() {
        return userDao.selectList(new QueryWrapper<>());
    }

    public User selectById(Long id) {
        return userDao.selectById(id);
    }

    public List<User> selectByName(String name) {
        return userDao.selectList(new QueryWrapper<User>().like("name", name));
    }

    public int delete(Long id) {
        return userDao.deleteById(id);
    }

    public int selectCount() {
        return userDao.selectCount(new QueryWrapper<>());
    }

    public List<User> selectByLike(String str) {
        str = StringUtils.hasText(str) ? "%" + str + "%" : "%%";
        return userDao.selectList(new QueryWrapper<User>().like("name", str));
    }
}
